package hiho.ku._1081;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	private static final int BIGINT = 99999999;

	private static class Edge {
		int next;
		int distance;

		public Edge(int next, int distance) {
			super();
			this.next = next;
			this.distance = distance;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int s = in.nextInt();
		int t = in.nextInt();
		Map<Integer, List<Edge>> map = new HashMap<Integer, List<Edge>>();
		for (int i = 0; i < m; i++) {
			int x = in.nextInt();
			int y = in.nextInt();
			int d = in.nextInt();
			if (!map.containsKey(x))
				map.put(x, new ArrayList<Edge>());
			map.get(x).add(new Edge(y, d));
			if (!map.containsKey(y))
				map.put(y, new ArrayList<Edge>());
			map.get(y).add(new Edge(x, d));
		}
		
		int[] distances = new int[n + 1];
		boolean[] checked = new boolean[n + 1];
		for (int i = 0; i <= n; i++)
			distances[i] = BIGINT;
		distances[s] = 0;
		while (true) {
			int now = 0;
			for (int i = 1; i <= n; i++)
				if (!checked[i] && distances[i] < distances[now])
					now = i;
			if (now == t)
				break;
			checked[now] = true;
			for (Edge edge : map.get(now))
				if (!checked[edge.next])
					distances[edge.next] = Math.min(distances[edge.next], distances[now] + edge.distance);
		}
		System.out.println(distances[t]);
	}

}
